package com.itboye.mengwu.app.ui.roof;

import java.util.ArrayList;
import java.util.List;
import java.util.Observable;
import java.util.Observer;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import android.R.integer;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.google.gson.Gson;
import com.itboye.config.GlobalConfig;
import com.itboye.core.object.BaseFragment;
import com.itboye.core.object.ResultEntity;
import com.itboye.core.utils.MyRunnable;
import com.itboye.core.utils.XImageLoader;
import com.itboye.core.utils.XPicasso;
import com.itboye.mengwu.R;
import com.itboye.mengwu.app.ui.aiwujia.ActivityZengWuXianYouKe;
import com.itboye.mengwu.app.ui.main.GoodsDetailActivity;
import com.itboye.mengwu.app.ui.main.GoodsListActivity;
import com.itboye.mengwu.app.ui.roof.HomePageItemFragmentTypeTwo.myListviewAdapter;
import com.itboye.mengwu.app.ui.roof.HomePageItemFragmentTypeTwo.viewHolder;
import com.itboye.mengwu.app.ui.web.WebActivity;
import com.itboye.mengwu.data.model.AppHeadPage;
import com.itboye.mengwu.data.model.CarouselPictureBean;
import com.itboye.mengwu.data.model.HomePageModel;
import com.itboye.mengwu.data.model.HomeTypeTwoModel;
import com.itboye.mengwu.data.model.LunBoModel;
import com.itboye.mengwu.data.presenter.HomePagePresenter;
import com.itboye.mengwu.data.presenter.LunBoPresenter;
import com.itboye.mengwu.luntan.comment.view.MyListView;
import com.itboye.mengwu.main.MainActivity;
import com.itboye.mengwu.main.MatchBuyActivity;
import com.itboye.mengwu.widget.CarouselView;
import com.itboye.mengwu.widget.MyGridView;
import com.itboye.mengwu.widget.XScrollView;
import com.squareup.picasso.Picasso;

public class HomPageItemFragment extends BaseFragment implements Observer,
		OnClickListener {

	CarouselView topLunbo;
	public XScrollView xScrollView;
	private List<ImageView> bmps;
	// private GridView gvVideoPlayBack;
	private MyGridView gridview_top;
	List<LunBoModel> boModel;
	LunBoPresenter lunBoPresenter;
	AppHeadPage page;
	ImageView ad_one;
	TextView txt_reloading;
	LinearLayout linBaoShuiQu;
	LinearLayout matchBuyLayout;
	String imageid;
	ImageView img1, img2, img3, img4, img5;
	ImageView hot1, hot2, hot3, hot4;
	ArrayList<String> imagesGrid = new ArrayList<String>();
	ArrayList<String> imagesDapei = new ArrayList<String>();
	ArrayList<String> imagesHot = new ArrayList<String>();
	ArrayList<String> imagesList = new ArrayList<String>();
	ArrayList<String> goodsName = new ArrayList<String>();
	ArrayList<String> goodsPrice = new ArrayList<String>();
	ArrayList<String> goodsPid = new ArrayList<String>();
	int pageSize = 1;
	TextView tv1, tv2, tv3, tv4, tv5, tv6;
	ImageView baosuiqu_img, dapeigou_img, temaihui_img, xianliangou;
	String APP_URL = "http://www.moodwo.com/index.php/Webview";
	String blok5;
	String blok6;
	String blokdan;
	String blokdan2;
	String blok4;
	ArrayList<String> bannerNamedan = new ArrayList<String>();
	ArrayList<String> bannerNamedan2 = new ArrayList<String>();
	ArrayList<String> bannerName4 = new ArrayList<String>();
	ArrayList<String> bannerName5 = new ArrayList<String>();
	ArrayList<String> bannerName6 = new ArrayList<String>();
	// LinearLayout list;
	// ImageView ad_two;
	// String adtwo;
	HomeTypeTwoModel homeTypeTwoModel = new HomeTypeTwoModel();
	ArrayList<HomeTypeTwoModel> arrayList2 = new ArrayList<HomeTypeTwoModel>();
	MyListView mylistview;

	@Override
	public int initView() {
		// TODO Auto-generated method stub
		return R.layout.aatodayspecialoffer;
	}

	@Override
	public void onMyActivityCreated() {
		xScrollView.smoothScrollTo(0, 0);
		HomePagePresenter homePagePresenter = new HomePagePresenter(this);
		homePagePresenter.appHead(pageSize + "");
		homePagePresenter.lunbo(6045);
		setOnitemLCickListener();

	}

	@Override
	public void onSaveInstanceState(Bundle outState) {
		// TODO Auto-generated method stub
		// super.onSaveInstanceState(outState);
	}

	private void setOnitemLCickListener() {
		xScrollView.smoothScrollTo(0, 0);
		// TODO Auto-generated method stub
		gridview_top.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> parent, View view,
					int position, long id) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(getActivity(), WebActivity.class);
				intent.putExtra("title", bannerName6.get(position));
				intent.putExtra("url", APP_URL + "/viewPage/index/block/"
						+ blok6 + "/banner/" + position + "");
				startActivity(intent);
			}
		});

		baosuiqu_img.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				// Intent intent = new Intent(getActivity(),
				// ActivityBaoShuiQu.class);
				// intent.putExtra("special", 1);
				// startActivity(intent);
				Intent intent = new Intent(getActivity(), WebActivity.class);
				intent.putExtra("title", "保税区");
				intent.putExtra("url", GlobalConfig.Web_URL + blok4
						+ "/banner/0");
				startActivity(intent);
			}
		});
		dapeigou_img.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(getActivity(), WebActivity.class);
				intent.putExtra("title", "搭配购");
				intent.putExtra("url", GlobalConfig.Web_URL + blok4
						+ "/banner/1");
				startActivity(intent);
			}
		});
		temaihui_img.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(getActivity(), WebActivity.class);
				intent.putExtra("title", "特卖汇");
				intent.putExtra("url", GlobalConfig.Web_URL + blok4
						+ "/banner/2");
				startActivity(intent);
			}
		});
		xianliangou.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(getActivity(), WebActivity.class);
				intent.putExtra("title", "限量购");
				intent.putExtra("url", GlobalConfig.Web_URL + blok4
						+ "/banner/3");
				startActivity(intent);
			}
		});
	}

	public class GridViewTopAdapter extends BaseAdapter {
		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return 6;
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return position;
			// arrayList == null ? new ArrayList<ProductTypeBean>()
			// : arrayList.get(position);
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			MyHolder holder = null;
			if (convertView == null) {
				holder = new MyHolder();
				LayoutInflater layoutInflater = LayoutInflater
						.from(getActivity());
				convertView = layoutInflater.inflate(
						R.layout.homepage_gridview_top_item, null);
				holder.img = (ImageView) convertView
						.findViewById(R.id.ItemImage);

				convertView.setTag(holder);
			} else {
				holder = (MyHolder) convertView.getTag();
			}
			holder.img.setScaleType(ScaleType.FIT_XY);
			// XImageLoader.load(GlobalConfig.API_URL + "/picture/index?id="
			// + imagesGrid.get(position), holder.img);
			XPicasso.loadImage(getActivity(), holder.img, GlobalConfig.API_URL
					+ "/picture/index?id=" + imagesGrid.get(position));
			// showImage2(GlobalConfig.API_URL
			// + "/picture/index?id=" + imagesGrid.get(position), holder.img);
			// XPicasso.loadBigImage(getActivity(), holder.img,
			// GlobalConfig.API_URL + "/picture/index?id="
			// + imagesGrid.get(position));
			return convertView;
		}

		public class MyHolder {
			private ImageView img;
		}

	}

	// @Override
	// public void onResume() {
	// // TODO Auto-generated method stub
	// super.onResume();
	// xScrollView.smoothScrollTo(0, 0);
	// }

	int position;

	@SuppressWarnings({ "unchecked", "deprecation" })
	@Override
	public void update(Observable observable, Object data) {
		ResultEntity model = super.handlerError(data);
		xScrollView.smoothScrollTo(0, 0);
		if (model != null) {
			if (model.getEventType() == HomePagePresenter.BannerSuccessEvent) {
				page = (AppHeadPage) model.getData();
				for (int j = 0; j < page.getItem_data().size(); j++) {
					String dataString = (String) page.getItem_data().get(j)
							.getData();
					try {
						JSONObject jsonObject = new JSONObject(dataString);
						String block_id = jsonObject.getString("block_id");
						String block_name = jsonObject.getString("block_name");
						JSONArray bannArray = jsonObject
								.getJSONArray("banners");
						for (int i = 0; i < bannArray.length(); i++) {
							JSONObject banners = bannArray.getJSONObject(i);
							int key = banners.getInt("key");
							String id = banners.getString("id");
							String name = banners.getString("name");
							// int width = banners.getInt("width");
							// int height = banners.getInt("height");
							// JSONObject groupJsonObject = banners
							// .getJSONObject("product_group");

							JSONObject grouplistJsonObject = banners
									.getJSONObject("group_product_list");

							// String max = groupJsonObject.getString("max");
							// ArrayList<String> product_ids =
							// (ArrayList<String>)
							// groupJsonObject
							// .get("product_ids");

							// String[] pidsString = grouplistJsonObject
							// .get("p_ids");

							// JSONArray skuArray = grouplistJsonObject
							// .getJSONArray("sku");
							// JSONObject skuJsonObject =
							// skuArray.getJSONObject(0);
							// String keyString =
							// skuJsonObject.getString("key");
							// String idString = skuJsonObject.getString("id");
							// String nameString =
							// skuJsonObject.getString("name");
							// String skuid = skuJsonObject.getString("sku_id");
							// String end_time =
							// skuJsonObject.getString("end_time");
							// String start_time =
							// skuJsonObject.getString("start_time");
							// String price = skuJsonObject.getString("price");
							// String indexForSort =
							// skuJsonObject.getString("indexForSort");
							// String display_order = skuJsonObject
							// .getString("display_order");
							if (j == 0) {
								imagesDapei.add(id);
								blok4 = block_id;
								bannerName4.add(name);
							}
							if (j == 1) {
								imageid = id;
								blokdan = block_id;
								bannerNamedan.add(block_name);
							}
							if (j == 2) {
								imagesGrid.add(id);
								blok6 = block_id;
								bannerName6.add(name);

							}
							if (j == 3) {
								imagesHot.add(id);
								blok5 = block_id;
								bannerName5.add(name);
								ArrayList<String> hh = new ArrayList<>();
								hh.add(key + "");
							}
							if (j >= 4) {

								Gson gson = new Gson();
								homeTypeTwoModel = gson.fromJson(page
										.getItem_data().get(j).getData()
										+ "", HomeTypeTwoModel.class);
								arrayList2.add(homeTypeTwoModel);
								Log.e("hu", arrayList2.size() + ",234");
								myListviewAdapter adapter = new myListviewAdapter(
										getActivity(), arrayList2);
								// adtwo,goodsName.size());
								mylistview.setAdapter(adapter);
							}

						}
					} catch (JSONException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					// showImage(imageid, ad_one);
					XPicasso.loadBigImage(getActivity(), ad_one,
							GlobalConfig.API_URL + "/picture/index?id="
									+ imageid);

					// showImage(adtwo, ad_two);
					// XPicasso.loadBigImage(getActivity(), ad_two,
					// GlobalConfig.API_URL + "/picture/index?id=" + adtwo);
					ad_one.setOnClickListener(new OnClickListener() {

						@Override
						public void onClick(View v) {
							// TODO Auto-generated method stub
							Intent intent2 = new Intent(getActivity(),
									WebActivity.class);
							intent2.putExtra("title", bannerNamedan.get(0));
							intent2.putExtra("url", APP_URL
									+ "/viewPage/index/block/" + blokdan
									+ "/banner/" + 0 + "");
							startActivity(intent2);
						}
					});
					// ad_two.setOnClickListener(new OnClickListener() {
					//
					// @Override
					// public void onClick(View v) {
					// // TODO Auto-generated method stub
					// Intent intent2 = new Intent(getActivity(),
					// WebActivity.class);
					// intent2.putExtra("title", bannerNamedan2.get(0));
					// intent2.putExtra("url", APP_URL
					// + "/viewPage/index/block/" + blokdan2
					// + "/banner/" + 0 + "");
					// startActivity(intent2);
					// }
					// });
					GridViewTopAdapter adapter1 = new GridViewTopAdapter();

					gridview_top.setAdapter(adapter1);
					// for (int i = 0; i < goodsName.size(); i++) {
					//
					// TextView[] pname = new TextView[goodsName.size()];
					// TextView[] price = new TextView[goodsPrice.size()];
					// ImageView[] img = new ImageView[imagesList.size()];
					// View view = LayoutInflater.from(getActivity()).inflate(
					// R.layout.topview, null);
					// ImageView imageView = (ImageView) view
					// .findViewById(R.id.hot);
					// TextView textView = (TextView) view
					// .findViewById(R.id.tv1);
					// TextView textView2 = (TextView) view
					// .findViewById(R.id.tv2);
					// textView.setText(goodsName.get(i));
					// textView2.setText("￥" + goodsPrice.get(i));
					// showImage(imagesList.get(i), imageView);
					// textView.setGravity(Gravity.CENTER);
					// textView.setTextColor(getResources().getColor(
					// R.color.black));
					// img[i] = imageView;
					// img[i].setTag(i);
					// android.widget.LinearLayout.LayoutParams lp = new
					// android.widget.LinearLayout.LayoutParams(
					// android.widget.LinearLayout.LayoutParams.WRAP_CONTENT,
					// android.widget.LinearLayout.LayoutParams.WRAP_CONTENT);
					// lp.setMargins(10, 10, 10, 10);
					// // list.addView(view, lp);
					// img[i].setOnClickListener(new OnClickListener() {
					//
					// @Override
					// public void onClick(View v) {
					// // TODO Auto-generated method stub
					// Intent intent = new Intent(getActivity(),
					// GoodsDetailActivity.class);
					// intent.putExtra("pid",
					// goodsPid.get((int) v.getTag()));
					// startActivity(intent);
					// }
					// });
					//
					// // list.
					// }
				}
				showImageB(imagesHot.get(0), img1);
				showImageB(imagesHot.get(1), img2);
				showImageB(imagesHot.get(2), img3);
				showImageB(imagesHot.get(3), img4);
				showImageB(imagesHot.get(4), img5);
				showImage(imagesDapei.get(0), baosuiqu_img);
				showImage(imagesDapei.get(1), dapeigou_img);
				showImage(imagesDapei.get(2), temaihui_img);
				showImage(imagesDapei.get(3), xianliangou);
				xScrollView.smoothScrollTo(0, 0);

			} else if (model.getEventType() == HomePagePresenter.LunBoSuccessEvent) {
				xScrollView.smoothScrollTo(0, 0);
				final ArrayList<LunBoModel> boModels = (ArrayList<LunBoModel>) model
						.getData();
				bmps = new ArrayList<ImageView>();
				for (int i = 0; i < boModels.size(); i++) {
					position = i;
					ImageView imageView = new ImageView(getActivity());
					imageView.setScaleType(ScaleType.FIT_XY);
					// com.nostra13.universalimageloader.core.ImageLoader
					// .getInstance().displayImage(
					// GlobalConfig.API_URL + "/picture/index?id="
					// + boModels.get(i).getImg(),
					// imageView);
					XPicasso.loadImage(getActivity(), imageView,
							GlobalConfig.API_URL + "/picture/index?id="
									+ boModels.get(i).getImg());
					bmps.add(imageView);
					imageView.setTag(i);
					imageView.setOnClickListener(new OnClickListener() {

						@Override
						public void onClick(View v) {
							// TODO Auto-generated method stub
							if ("6071".equals(boModels.get((int) v.getTag())
									.getUrl_type())) {
								Intent intent = new Intent(getActivity(),
										GoodsDetailActivity.class);
								intent.putExtra("pid",
										boModels.get((int) v.getTag()).getUrl());
								startActivity(intent);
							} else if ("6070".equals(boModels.get(
									(int) v.getTag()).getUrl_type())) {
								Intent intent = new Intent(getActivity(),
										WebActivity.class);
								intent.putExtra("url",
										boModels.get((int) v.getTag()).getUrl());
								intent.putExtra("title",
										boModels.get((int) v.getTag())
												.getTitle());
								startActivity(intent);
							} else if ("6072".equals(boModels.get(
									(int) v.getTag()).getUrl_type())) {
								Intent intent = new Intent(getActivity(),
										WebActivity.class);
								intent.putExtra("tid",
										boModels.get((int) v.getTag()).getUrl());
								intent.putExtra("title",
										boModels.get((int) v.getTag())
												.getTitle());
								startActivity(intent);
							} else if ("6159".equals(boModels.get(
									(int) v.getTag()).getUrl_type())) {
								Intent intent = new Intent(getActivity(),
										WebActivity.class);
								intent.putExtra("tid",
										boModels.get((int) v.getTag()).getUrl());
								intent.putExtra("title",
										boModels.get((int) v.getTag())
												.getTitle());
								startActivity(intent);
							} else if ("6160".equals(boModels.get(
									(int) v.getTag()).getUrl_type())) {
								Intent intent = new Intent(getActivity(),
										ActivityZengWuXianYouKe.class);
								intent.putExtra("pid",
										boModels.get((int) v.getTag()).getUrl());
								// intent.putExtra("title",
								// boModels.get((int) v.getTag())
								// .getTitle());
								startActivity(intent);
							} else if ("6161".equals(boModels.get(
									(int) v.getTag()).getUrl_type())) {
								Intent intent = new Intent(getActivity(),
										WebActivity.class);
								intent.putExtra("tid",
										boModels.get((int) v.getTag()).getUrl());
//								intent.putExtra("title",
//										boModels.get((int) v.getTag())
//												.getTitle());
								startActivity(intent);
							}

						}
					});
				}
				topLunbo.setImageBitmaps(bmps);
				// //让顶部控件获取到焦点这样滚动条就自然停在顶部了
				topLunbo.setFocusable(true);
				topLunbo.setFocusableInTouchMode(true);
				topLunbo.requestFocus();
				xScrollView.smoothScrollTo(0, 0);
				txt_reloading.setVisibility(View.GONE);
			}
		}
		xScrollView.smoothScrollTo(0, 0);
	}

	private void showImage2(String imageid2, ImageView ad_one2) {
		// TODO Auto-generated method stub
		ad_one2.setScaleType(ScaleType.FIT_XY);
		XImageLoader.load(GlobalConfig.API_URL + "/picture/index?id="
				+ imageid2, ad_one2);

	}

	private void showImageB(String imageid2, ImageView ad_one2) {
		// TODO Auto-generated method stub
		// ad_one2.setScaleType(ScaleType.FIT_XY);
		XPicasso.loadBigImage(getActivity(), ad_one2, GlobalConfig.API_URL
				+ "/picture/index?id=" + imageid2);
	}

	private void showImage(String imageid2, ImageView ad_one2) {
		// TODO Auto-generated method stub
		// XImageLoader.load(GlobalConfig.API_URL + "/picture/index?id="
		// + imageid2, ad_one2);
		// if (MainActivity.WIDTH <= 900) {
		// ad_one2.setScaleType(ScaleType.FIT_XY);
		XPicasso.loadImage(getActivity(), ad_one2, GlobalConfig.API_URL
				+ "/picture/index?id=" + imageid2);
		// } else {
		// ad_one2.setScaleType(ScaleType.FIT_XY);
		// XPicasso.loadBigImage(getActivity(), ad_one2, GlobalConfig.API_URL
		// + "/picture/index?id=" + imageid2);
		// }

	}

	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		switch (v.getId()) {
		case R.id.img1:
			Intent intent = new Intent(getActivity(), WebActivity.class);
			intent.putExtra("title", bannerName5.get(0));
			intent.putExtra("url", APP_URL + "/viewPage/index/block/" + blok5
					+ "/banner/" + 0 + "");
			startActivity(intent);
			break;
		case R.id.img2:
			Intent intent2 = new Intent(getActivity(), WebActivity.class);
			intent2.putExtra("title", bannerName5.get(1));
			intent2.putExtra("url", APP_URL + "/viewPage/index/block/" + blok5
					+ "/banner/" + 1 + "");
			startActivity(intent2);
			break;
		case R.id.img3:
			Intent intent3 = new Intent(getActivity(), WebActivity.class);
			intent3.putExtra("title", bannerName5.get(2));
			intent3.putExtra("url", APP_URL + "/viewPage/index/block/" + blok5
					+ "/banner/" + 2 + "");
			startActivity(intent3);
			break;
		case R.id.img4:
			Intent intent4 = new Intent(getActivity(), WebActivity.class);
			intent4.putExtra("title", bannerName5.get(3));
			intent4.putExtra("url", APP_URL + "/viewPage/index/block/" + blok5
					+ "/banner/" + 3 + "");
			startActivity(intent4);
			break;
		case R.id.img5:
			Intent intent5 = new Intent(getActivity(), WebActivity.class);
			intent5.putExtra("title", bannerName5.get(4));
			intent5.putExtra("url", APP_URL + "/viewPage/index/block/" + blok5
					+ "/banner/" + 4 + "");
			startActivity(intent5);
			break;

		default:
			break;
		}
	}

	class myListviewAdapter extends BaseAdapter {
		Context context;
		ArrayList<HomeTypeTwoModel> arrayList2;

		public myListviewAdapter(Context context,
				ArrayList<HomeTypeTwoModel> arrayList2) {
			// TODO Auto-generated constructor stub
			this.context = context;
			this.arrayList2 = arrayList2;
		}

		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return arrayList2.size();
		}

		@Override
		public Object getItem(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public View getView(final int position, View convertView,
				ViewGroup parent) {
			// TODO Auto-generated method stub
			viewHolder holder = null;
			if (convertView == null) {
				holder = new viewHolder();
				convertView = LayoutInflater.from(context).inflate(
						R.layout.item_homepagetypetwo, null);
				holder.ad_two = (ImageView) convertView
						.findViewById(R.id.ad_two);
				holder.list = (LinearLayout) convertView
						.findViewById(R.id.list);
				XPicasso.loadBigImage(context, holder.ad_two,
						GlobalConfig.API_URL
								+ "/picture/index?id="
								+ arrayList2.get(position).getBanners().get(0)
										.getId());
				// Log.e("hu",
				// arrayList2.get(position).getBlockId()+">>>>"+arrayList2.get(position).getBanners().get(0)
				// .getId());
				// Log.e("hu....", position+"");
				holder.ad_two.setOnClickListener(new OnClickListener() {

					@Override
					public void onClick(View v) {
						// TODO Auto-generated method stub
						Intent intent2 = new Intent(getActivity(),
								WebActivity.class);
						intent2.putExtra("title", arrayList2.get(position)
								.getBanners().get(0).getName());
						intent2.putExtra("url",
								APP_URL + "/viewPage/index/block/"
										+ arrayList2.get(position).getBlockId()
										+ "/banner/" + 0 + "");
						Log.e("hu blockid", arrayList2.get(position)
								.getBlockId() + "");
						startActivity(intent2);
					}
				});
				holder.list.removeAllViews();
				if (arrayList2.get(position).getBanners().size() > 0) {
					if (arrayList2.get(position).getBanners().get(0)
							.getProductHome() != null) {
						for (int m = 0; m < arrayList2.get(position)
								.getBanners().get(0).getProductHome()
								.getProductInfo().size(); m++) {

							ImageView[] mimg = new ImageView[arrayList2
									.get(position).getBanners().get(0)
									.getProductHome().getProductInfo().size()];
							View view = LayoutInflater.from(getActivity())
									.inflate(R.layout.topview, null);
							ImageView imageView = (ImageView) view
									.findViewById(R.id.hot);
							TextView textView = (TextView) view
									.findViewById(R.id.tv1);
							TextView textView2 = (TextView) view
									.findViewById(R.id.tv2);
							textView.setText(arrayList2.get(position)
									.getBanners().get(0).getProductHome()
									.getProductInfo().get(m).getName());
							textView2
									.setText("￥"
											+ arrayList2.get(position)
													.getBanners().get(0)
													.getProductHome()
													.getProductInfo().get(m)
													.getPrice());
							showImage(arrayList2.get(position).getBanners()
									.get(0).getProductHome().getProductInfo()
									.get(m).getImg(), imageView);
							textView.setGravity(Gravity.CENTER);
							textView.setTextColor(getResources().getColor(
									R.color.black));
							mimg[m] = imageView;
							mimg[m].setTag(m);
							android.widget.LinearLayout.LayoutParams lP = new android.widget.LinearLayout.LayoutParams(
									android.widget.LinearLayout.LayoutParams.WRAP_CONTENT,
									android.widget.LinearLayout.LayoutParams.WRAP_CONTENT);
							lP.setMargins(10, 10, 10, 10);
							holder.list.addView(view, lP);
							mimg[m].setOnClickListener(new OnClickListener() {

								@Override
								public void onClick(View v) {
									// TODO Auto-generated method stub
									Intent intent = new Intent(getActivity(),
											GoodsDetailActivity.class);
									intent.putExtra(
											"pid",
											arrayList2.get(position)
													.getBanners().get(0)
													.getProductHome()
													.getProductInfo()
													.get((int) (v.getTag()))
													.getProductId());

									// goodsPid.get((int) v.getTag()));
									startActivity(intent);
								}
							});

						}
					}
				}

				convertView.setTag(holder);
			} else {
				holder = (viewHolder) convertView.getTag();
			}
			return convertView;
		}
	}

	class viewHolder {
		ImageView ad_two;
		LinearLayout list;
	}
}
